package com.example.demo.controller.system;

import com.example.demo.annoation.Log;
import com.example.demo.bean.AjaxRes;
import com.example.demo.bean.log.SysOperLogDO;
import com.example.demo.bean.sysuser.SysUserDO;
import com.example.demo.controller.BaseAdminController;
import com.example.demo.dto.log.SysLoginLogPageReqVO;
import com.example.demo.dto.log.SysOperLogPageReqVO;
import com.example.demo.enums.BusinessType;
import com.example.demo.service.ISysLoginLogService;
import com.example.demo.service.ISysOperLogService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RequestMapping(value = "/system/sys_oper_log")
@RestController
public class SysOperLogController extends BaseAdminController {

    @Resource
    private ISysOperLogService sysOperLogService;

    @GetMapping("/list")
    public AjaxRes list(SysOperLogPageReqVO sysOperLogPageReqVO) {
        return AjaxRes.success(sysOperLogService.list(sysOperLogPageReqVO));
    }

    @DeleteMapping("/delete/{logIds}")
    @Log(title = "删除操作日志", businessType = BusinessType.DELETE)
    public AjaxRes delete(@PathVariable("logIds") Long[] logIds) {
        return toAjax(sysOperLogService.deleteOperLog(logIds));
    }

    @DeleteMapping("/clear")
    @Log(title = "清空操作日志", businessType = BusinessType.DELETE)
    public AjaxRes clear(){
        sysOperLogService.clearOperLog();
        return success();
    }

    @GetMapping("/{operId}")
    public AjaxRes query(@PathVariable("operId") Long operId) {
        return AjaxRes.success(sysOperLogService.getSysOperLog(new SysOperLogDO().setOperId(operId)));
    }
}
